package com.qire.manhua.model.enumeration;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.basic.StringUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.utils.Logger;
import com.qire.manhua.model.entity.ComicBookEntity;

/**
 * 应用平台内banner广告类型
 */
public enum AdActionType {

    ToWebPage(0, AdActionType::toWebPage),
    ToComicDetail(1, AdActionType::toComicDetail),
    ToComicReader(2, AdActionType::toComicReader);

    public final int    type;
    public final Action action;

    AdActionType(int type, Action action){
        this.type   = type;
        this.action = action;
    }

    public static AdActionType build(int type) {
        switch (type) {
            case 0 :
                return ToWebPage;
            case 1 :
                return ToComicDetail;
            case 2 :
                return ToComicReader;
        }
        return null;
    }

    public static void toWebPage(Object... params) {
        Logger.d("打开网页");
        String adUrl    = (String)params[0];
        String adTitle  = (String)params[1];
        if(StringUtil.isEmpty(adUrl)) {
            return;
        }
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.WebPage)
                .withData("url", adUrl)
                .withData("title", adTitle)
                .navigation();
    }
    public static void toComicDetail(Object... params) {
        Logger.d("进入书籍详情页面");
        ComicBookEntity comicBookEntity = (ComicBookEntity)params[0];
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicDetailPage)
                .withData("comicBookId", comicBookEntity.id)
                .navigation();
    }
    public static void toComicReader(Object... params) {
        Logger.d("打开阅读页");
        ComicBookEntity comicBookEntity = (ComicBookEntity)params[0];
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicReaderPage)
                .withData("comicBookEntity", comicBookEntity)
                .navigation();
    }

    public interface Action {
        void doAction(Object... params);
    }

}
